package org.cxmzxy.zhlxyj;

class YieldThread extends Thread{
    public YieldThread(String name){
        super(name);
    }

    @Override
    public void run() {
        for (int i =1;i<4;i++){
            String threadName = Thread.currentThread().getName();
            if (i == 2){
                System.out.println(threadName+"线程让步！");
                Thread.yield();
            }
            System.out.println(threadName+"---"+i);
        }
    }
}
public class Example05 {
    public static void main(String[] args){
        Thread thread1 = new YieldThread("thread1");
        Thread thread2 = new YieldThread("thread2");
        thread1.start();
        thread2.start();
    }
}
